// Test namespace. Delete ...
YAHOO.namespace("example.container");
/*
 * Namespaces and Global configurarion
 */
YAHOO.namespace("karyoDas");
YAHOO.karyoDas =
{
	conf: {
		selectedDsnId: "",
		userEntryPoints: new Array(),
		userContainers: new Array(),
		zoomConf: new Array(),
		sources: new Array()
	}
}

YAHOO.namespace ("dasBrowser");
YAHOO.dasBrowser = {
	dasRegistry: {
		parse: function(){}
	},
	yuiContainer: {
		module: new Array(),
		overlay: new Array(),
		panel: new Array(),
		dialog: new Array(),
		loadingWindow: true
	},
	proxy: {
		parameters: {
			source: "s"
		}
	},
	util: {
		printOnTest: function(){},
		displayObjProp: function(){},
		assocSort: function(){},
		addPxSuffix: function(){},
		deletePxSuffix: function() {},
		isItanOddNumber: function() {},
		getDivBackgroundColor: function() {}
	},
	genome: {
		setInput: function(){},
		setDefaultInput: function(){},
		view: {
			copyNumber: {
				start: function(){},
				drawCopyNumberViewStructure: function(){},
				tree: null,
				treeData: null
			}
		},
		panel:{ // change to panelTitle
			userContainers: new Array(),
			setContainers: function(){},
			defaultContainers: {
				karyotypeView: "Karyotype",
				chromosomeView: "Chromosome",
				bandView: "Band",
				zoomView: "Zoom",
				sequenceView: "Sequence",
				annotationListView: "Annotations",
				copyNumberView: "Copy Number",
				test: "Test"
			},
			setPanelListeners: function(){},
			panelDisplay: function(){},
			//container: new Array(),
			title: {
				fontSizePx: 12,
				fontWeight: 'bold',
				borderBottom: '1px solid #000000',
				//borderBottom: '1px solid #000000',
				backgroundColor: '#e7e9ee',
				//backgroundColor: '#E5E5E5',
				//backgroundColor: '#f2f2f2',
				//backgroundColor: '#182c55',
				//backgroundColor: '#edf5ff',
				//fontColor: '#FFFFFF',
				fontColor: '#000000',
				marginBottom: 0,
				marginTop: 0,
				padding: 1
			}
		},
		annotations:{
			mappingRequestIdAnnotationSource: new Array(),
			setPopupListener: function() {},
			setScores: function() {},
			sources: new Array(),
			/*sources:{
				karyotype: new Array(),
				chromosome: new Array(),
				band: new Array(),
			},*/
			chromosomeSources: new Array(),
			bandSources: new Array(),
			segmentSourcesFailed: 0,
			mappingRequestIdSource: new Array(),
			showDetailView: true,
			showSimpleView: true,
			showGeneralView: true,
			detailView: null,
			simpleView: {
				drawLegend: function() {},
				arrowLimitPx: 3,
				//annotationHeight: 3,
				//annotationHeight2: 25,
				annotationPaddingBottom: 2,
				mappingSourcesToPosition: new Array(),
				maxAnnotationSources: 8,
				annotationColors: ['cc0000','0000cc','006666','ff6600','5d005d','007f00','7f0000','00007f','d700d7','827f00']
			},
			generalView: null
		},
		karyotypeStructure: {
			test: false,
			setTestValues: function(){},
			referenceUrl: "http://www.ensembl.org/das/",
			//referenceUrl: "http://ensembl.genomics.org.cn/das/",
			//proxyUrl: "proxy.php",
			proxyUrl: "../perl/proxy",
			//proxyUrl: "../../cgi-bin/proxy.cgi",
			//proxyUrl: "dasproxy",
			sequence: {
				parse: function(){}
			},
			dsn: {
				selectedDsn: {
					id: "Homo_sapiens.GRCh37.reference",
					//id: "Canis_familiaris.BROADD2.reference",
					//id: "Rattus_norvegicus.RGSC3.4.reference",
					//id:"Aedes_aegypti.AaegL1.reference",
					referenceLocation: null,
					karyotypeLocation: null
				},
				allDsn: new Array(),
				test: false,
				testUrl: null,
				url: new String(),
				parseEnsemblDsn: function(){},
				splitEnsemblDsnSourceId: function(){}
			},
			entryPoints: {
				userEntryPoints: new Array(),
				ids: new Array(),
				selectedEntryPoints: {
					type: "chromosome",
					ids: new Array()
				},
				allEntryPoints: new Array(),
				test: false,
				testUrl: null,
				url: new String(),
				parseEnsemblEntryPoints: function(){}
			},
			karyotype: {
				zoom: new Object(),
				showZoom: true,
				showBand: true,
				showChromosome: true,
				showKaryotype: true,
				chromosomes: new Object(),
				spotZoomRegion: function(){},
				drawSequenceViewStructure: function(){},
				drawSequence: function(){},
				createChromosomeObjects: function(){},
				drawAnnotationListViewStructure: function(){},
				drawKaryotypeViewStructure: function(){},
				drawChromosomeViewStructure: function(){},
				drawChromosomePanelStructure: function(){},
				drawChromosome: function() {},
				drawChromosomeBands: function() {},
				drawChromosomeSimpleAnnotation: function() {},
				drawAnnotations: function() {},
				setAnnotationTooltip: function() {},
				getNumberOfChromosomeLabelLines: function() {},
				chromosomeLabelLinesPerPx: {0:0, 100:5, 250:4, 450:3, 700:2, 1400:1},
				labelFontSizePx: 9,
				chrLabelTopContainerPrefix: 'LabelTop',
				chrLabelBottomContainerPrefix: 'LabelBottom',
				chrLabelBandContainerPrefix: 'Bands',
				chromosomeLeftPaddingPx: 25, // Delete! ... this is already defined on YAHOO.dasBrowser.genome.karyotypeStructure.karyotype.panelContainer.chromosomeContainer.leftPaddingPx
				calculateKaryotypeChromosomeWidthPx: function(){},
				redrawChromosome: function(){},
				addRedrawChromosomeListener: function(){},
				redrawChromosomeCallback: function(){},
				sequenceConf:{
					fontSizePx: 11,
					length: 170,
					sequenceObject: null,
					callType: 0,
					test: false,
					widthPx: 1200,
					labelPrefix: "Sv",
					coordinates: {
						chromosomeId: null,
						start: null,
						end: null
					}
				},
				annotationListConf:{
					test: false,
					widthPx: 1200,
					labelPrefix: "Av"
					//selectedList: null,
				},
				zoomConf:{
					defaultValues: new Array(),
					numberOfZoomMarkSources: 0,
					start: 0,
					stop: 0,
					widthPx: 1200,
					heightPx: 8,
					layout: ['title','sourceLegend','details','chromosomeContainer','annotations'],
					labelPrefix: "Zv",
					featureNumber: 0,
					annotationLimit: 1200
				},
				bandConf:{
					//selectedBand: null,
					selectedBand: 8,
					mappingBandNamesToBandIds: new Array(),
					test: false,
					bandWidthPx: 1200,
					bandHeightPx: 8,
					layout: ['title','sourceLegend','details','chromosomeContainer','annotations', 'slider'],
					labelPrefix: "Bv",
					featureNumber: 0,
					annotationLimit: 1200
				},
				chromosomeConf:{
					selectedChromosome: null,
					test: false,
					testUrl: null,
					useCustomBandWidthPx: true,
					chromosomeWidthPx: 1200,
					chromosomeHeightPx: 15,
					layout: ['title','sourceLegend','details','chromosomeContainer','annotations', 'slider'],
					labelPrefix: "Cv",
					annotationLimit: 1200
				},
				karyotypeConf: {
					karyotypeColumns: 3,
					karyotypeColumnsMargin: 15,
					selectedChromosome: null,
					longestChromosome: null,
					mappingRequestIdChromosomeId: new Array(),
					mappingChrIdChrLength: new Array(),
					mappingChrIdChrWidhtPx: new Array(),
					chromosomeProportion: new Number(),
					useCustomChromosomeWidthPx: true,
					chromosomeWidthPx: 1000,
					chromosomeHeightPx: 8,
					chromosomeShowIdLabels: false,
					layout: ['title','sourceLegend','details','chromosomeContainer','annotations'],
					labelPrefix: "Kv",
					annotationLimit: 300,
					annotationLimitDisplay: 900
				},
				stylesheet: {
					useCustomStylesheet: true,
					allTypes: new Array(),
					test: false,
					testUrl: null,
					url: new String(),
					valuesAndColors: new Array(),
					setStylesheetValuesAndColors: function(){},
					setCustomValuesAndColors: function(){},
					parse: function(){}
				},
				panelContainer:{
					labelPrefix: 'Panel',
					marginLeft: 5,
					marginTop: 5,
					marginBottom: 11,
					titleContainer: {
						labelPrefix: 'Title',
						fontSizePx: 11,
						fontWeight: 'normal',
						borderBottom: '1px dotted #000000',
						backgroundColor: '#ffffff',
						marginBottom: 4,
						marginTop: 0
					},
					legendContainer: {
						labelPrefix: 'Legend'
					},
					detailsContainer: {
						labelPrefix: 'Details'
					},
					annotationContainer: {
						labelPrefix: 'Annot'
					},
					chromosomeContainer: {
						labelPrefix: 'Cont',
						leftPaddingPx: 35,
						topBandLabelContainer: {
							positionPrefix: 'Top',
							labelPrefix: 'BandLabel',
							visible_Zv: true,
							visible_Bv: false,
							visible_Cv: true,
							visible_Kv: false
						},
						bottomBandLabelContainer: {
							positionPrefix: 'Bottom',
							labelPrefix: 'BandLabel',
							visible_Zv: true,
							visible_Bv: false,
							visible_Cv: true,
							visible_Kv: false
						},
						topSimpleAnnotationContainer: {
							positionPrefix: 'Top',
							labelPrefix: 'SAnnot',
							height_Zv: 9,
							height_Bv: 9,
							height_Cv: 5,
							height_Kv: 3
						},
						bottomSimpleAnnotationContainer: {
							positionPrefix: 'Bottom',
							labelPrefix: 'SAnnot',
							height_Zv: 9,
							height_Bv: 9,
							height_Cv: 5,
							height_Kv: 3
						},
						topSimpleChartAnnotationContainer: {
							positionPrefix: 'Top',
							labelPrefix: 'SAnnotChart',
							height_Zv: 75,
							height_Bv: 65,
							height_Cv: 55,
							height_Kv: 25
						},
						bottomSimpleChartAnnotationContainer: {
							positionPrefix: 'Bottom',
							labelPrefix: 'SAnnotChart',
							height_Zv: 75,
							height_Bv: 65,
							height_Cv: 55,
							height_Kv: 25
						},
						chromosomeRepresentationContainer: {
							labelPrefix: 'ChrRep',
							chromosomeBandContainer: {
								labelPrefix: 'Band'
							}
						},
						sourceLegendContainer: {
							labelPrefix: 'Legend'
						},
						sliderContainer: {
							labelPrefix: 'Slider'
						}
					}
				}
			}
		},
		sourceList: null,
		annotationSources: {
			external: null,
			internal: null,
			parseAnnotationFeatures: function(){}
		},
		request: {
			drawing: {
					chromosomeBands: {
						total: null,
						completed: 0
					},
					annotations: {
						total: null,
						completed: 0
					},
					isCompleted: function(){},
					allCompleted: false
			},
			startGenomeDasRequest: startGenomeDasRequest,
			makeEnsemblDsnRequest: function(){},
			makeEnsemblEntryPointsRequest: function(){},
			makeEnsemblKaryotypeStylesheetRequest: function(){},
			makeSourceStylesheetRequest: function(){},
			makeEnsemblChromosomeBandsRequest: function(){},
			makeAnnotationRequest: function(){},
			makeSequenceRequest: function(){},
			doAtTheEndOfLoading: function(){}
		}
	},
    protein: null
}

YAHOO.dasBrowser.genome.karyotypeStructure.setTestValues = function(){
	YAHOO.dasBrowser.genome.karyotypeStructure.dsn.test = true;
	YAHOO.dasBrowser.genome.karyotypeStructure.dsn.testUrl = "test/ensemblDsn.xml";
	YAHOO.dasBrowser.genome.karyotypeStructure.entryPoints.test = true;
	YAHOO.dasBrowser.genome.karyotypeStructure.entryPoints.testUrl = "test/ensemblEntry_points.xml";
	YAHOO.dasBrowser.genome.karyotypeStructure.karyotype.chromosomeConf.test = true;
	//YAHOO.dasBrowser.genome.karyotypeStructure.karyotype.chromosomeConf.testUrl = "test/ensemblChr22Bands.xml";
	//YAHOO.dasBrowser.genome.karyotypeStructure.karyotype.chromosomeConf.selectedChromosome = "chromosome22";
	YAHOO.dasBrowser.genome.karyotypeStructure.karyotype.chromosomeConf.testUrl = "test/ensemblChr1Bands.xml";
	YAHOO.dasBrowser.genome.karyotypeStructure.karyotype.chromosomeConf.selectedChromosome = "chromosome1";
	YAHOO.dasBrowser.genome.karyotypeStructure.karyotype.stylesheet.test = true;
	YAHOO.dasBrowser.genome.karyotypeStructure.karyotype.stylesheet.testUrl = "test/ensemblKaryotypeStylesheet.xml";
}


/*
 * start AJAX request control
 */
function startGenomeDasRequest(){
	YAHOO.dasBrowser.genome.setInput();
	YAHOO.dasBrowser.genome.panel.setContainers();
	YAHOO.dasBrowser.genome.request.doAtTheBeginningOfLoading();
	YAHOO.dasBrowser.genome.request.makeEnsemblDsnRequest();
}

YAHOO.dasBrowser.genome.setInput = function(){
	var karyoDasConf = false;
	if(typeof sessvars!="undefined"){
		if (typeof sessvars.karyoDas != "undefined") {
			karyoDasConf = true;
		}
	}
	
	if (karyoDasConf) {
		YAHOO.dasBrowser.genome.karyotypeStructure.dsn.selectedDsn.id = sessvars.karyoDas.conf.selectedDsnId;
		YAHOO.dasBrowser.genome.karyotypeStructure.karyotype.zoomConf.defaultValues = sessvars.karyoDas.conf.zoomConf;
		YAHOO.dasBrowser.genome.karyotypeStructure.entryPoints.userEntryPoints = sessvars.karyoDas.conf.userEntryPoints;
		YAHOO.dasBrowser.genome.panel.userContainers = sessvars.karyoDas.conf.userContainers;
		YAHOO.dasBrowser.genome.annotations.sources = sessvars.karyoDas.conf.sources;
	} else {
		//YAHOO.dasBrowser.genome.setDefaultInput();
		YAHOO.dasBrowser.genome.karyotypeStructure.dsn.selectedDsn.id = YAHOO.karyoDas.conf.selectedDsnId;
		YAHOO.dasBrowser.genome.karyotypeStructure.karyotype.zoomConf.defaultValues = YAHOO.karyoDas.conf.zoomConf;
		YAHOO.dasBrowser.genome.karyotypeStructure.entryPoints.userEntryPoints = YAHOO.karyoDas.conf.userEntryPoints;
		YAHOO.dasBrowser.genome.panel.userContainers = YAHOO.karyoDas.conf.userContainers;
		YAHOO.dasBrowser.genome.annotations.sources = YAHOO.karyoDas.conf.sources;
	}
}

function rafaTest(){
	alert("hello");
	//var dd1 = new YAHOO.util.DD("title");
	//var eChrFeature = new YAHOO.util.Element("resizablepanel2");
	var myPanel = new YAHOO.widget.Panel("resizablepanel2", {visible:false});
	myPanel.render();
	//eChrFeature.setStyle('display', 'block');
	
	
	//YAHOO.dasBrowser.genome.request.startGenomeDasRequest();
}

